/**
 * 
 */
package com.kth.subtranslator.ui;

import java.awt.AWTEvent;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * @author Kevin Thackray
 *
 */
public class EventQueueProxy extends EventQueue {

	private JFrame rootFrame;

	/**
	 * 
	 */
	public EventQueueProxy(JFrame rootFrame) {
		this.rootFrame = rootFrame;
	}
	
	protected void dispatchEvent(AWTEvent newEvent) {
		try {
			super.dispatchEvent(newEvent);
		} catch (Throwable t) {
			t.printStackTrace();
			String message = t.getMessage();

			if (message == null || message.length() == 0) {
				message = "Fatal: " + t.getClass();
			}

			JOptionPane.showMessageDialog(rootFrame, message, "Error", JOptionPane.ERROR_MESSAGE);
		}
	}
}
